package com.example.day2.busi.home;

import androidx.lifecycle.MutableLiveData;

import com.example.day2.entity.CommentFSParam;
import com.example.day2.entity.CommentFSResult;
import com.example.day2.entity.CommentResult;
import com.example.day2.entity.LiveResult;
import com.example.day2.entity.NoLiveReuslt;
import com.example.day2.entity.NormalResult;
import com.example.day2.entity.VideoResult;
import com.example.day2.mvvm.base.BaseRepo;
import com.example.day2.mvvm.base.GuanZhuParam;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

public class VideoRepo extends BaseRepo {

    public void getVideos(int page, int size, MutableLiveData<VideoResult> success, MutableLiveData<String> file){
        apiService.getVideo(page,size)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<VideoResult>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(VideoResult videoResult) {
                        success.setValue(videoResult);
                    }

                    @Override
                    public void onError(Throwable e) {
                            file.setValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });

    }
public void getGuanzhu(GuanZhuParam guanZhuParam, MutableLiveData<NormalResult> success,MutableLiveData<String> fail){
        apiService.getNormal(guanZhuParam)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<NormalResult>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(NormalResult normalResult) {
                        success.setValue(normalResult);
                    }

                    @Override
                    public void onError(Throwable e) {
                        fail.setValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
}
    public void getLive(int VideoId , MutableLiveData<LiveResult> success, MutableLiveData<String> fail) {
        apiService.getLive(VideoId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<LiveResult>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(LiveResult liveResult) {
                        success.setValue(liveResult);
                    }

                    @Override
                    public void onError(Throwable e) {
                        fail.setValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
    public void getNoLive(int VideoId , MutableLiveData<NoLiveReuslt> success, MutableLiveData<String> fail) {
        apiService.getNoLive(VideoId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<NoLiveReuslt>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(NoLiveReuslt noLiveReuslt) {
                        success.setValue(noLiveReuslt);
                    }

                    @Override
                    public void onError(Throwable e) {
                        fail.setValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }


    public void getCommentHQ(int viewID, MutableLiveData<CommentResult> success,MutableLiveData<String> fail){
        apiService.getCommentHQ(viewID)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<CommentResult>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(CommentResult commentResult) {
                        success.setValue(commentResult);
                    }

                    @Override
                    public void onError(Throwable e) {
                        fail.setValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

    public void getCommentFS(CommentFSParam commentFSParam, MutableLiveData<CommentFSResult> success,MutableLiveData<String> fail){
        apiService.getCommentFS(commentFSParam)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<CommentFSResult>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(CommentFSResult commentFSResult) {
                        success.setValue(commentFSResult);
                    }

                    @Override
                    public void onError(Throwable e) {
                        fail.setValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

}
